package home.projects.recipes.chapthree;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Repository;

@Repository("repository")
public class SequenceDAOImpl implements ISequenceDAO {

   private Map<String, Sequence> sequenceMap;
   
   private Map<String, Integer> valueMap;
   
   public SequenceDAOImpl() {
      sequenceMap = new HashMap<String, Sequence>();
      valueMap = new HashMap<String, Integer>();
      
      sequenceMap.put("SQ1", new Sequence("SQ1", "PRE", "SUF"));
      valueMap.put("SQ1", 1);
   }
   
   /* (non-Javadoc)
    * @see home.projects.recipes.chapthree.ISequenceDAO#getNextSequence(java.lang.String)
    */
   public synchronized int getNextValue(String sequenceId) {
      int val = valueMap.get(sequenceId);
      valueMap.put(sequenceId, val + 1);
      return val;
   }

   /* (non-Javadoc)
    * @see home.projects.recipes.chapthree.ISequenceDAO#getSequence(java.lang.String)
    */
   public Sequence getSequence(String sequenceId) {
      return sequenceMap.get(sequenceId);
   }

}
